﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Time
{
    class Time
    {
        const int MAXIMUM_MINUTES = 59;
        const int MAXMIMUM_HOURS = 23;
        const int MINUTES_IN_ONE_HOUR = 60;

        private int hours;
        private int minutes;

        public Time(int hours, int minutes)
        {
            this.Hours = hours;
            this.Minutes = minutes;
        }

        public int Hours
        {
            get
            {
                return hours;
            }
            set
            {
                hours = value;
            }
        }

        public int Minutes
        {
            get
            {
                return minutes;
            }
            set
            {
                minutes = value;
            }
        }

        public override string ToString()
        {
            string time = string.Format("{0}:{1}", this.hours, this.minutes);

            return time;
        }

        public static Time operator ++(Time time)
        {
            time += 1;
            return time;
        }

        public static Time operator --(Time time)
        {
            time -= 1;
            return time;
        }

        public static Time operator +(Time time, int minutes)
        {
            int timeInMunites = ConvertToMinutes(time.hours, time.minutes);
            int timeAfterAdditionInMinutes = timeInMunites + minutes;

            int hoursAfterConversion = 0;
            int minutesAfterConversion = 0;
            ConvertMinutesToHours(timeAfterAdditionInMinutes, out hoursAfterConversion, out minutesAfterConversion);

            Time timeAfterAddition = new Time(hoursAfterConversion , minutesAfterConversion);
            return timeAfterAddition;
        }

        public static Time operator -(Time time, int minutes)
        {
            int timeInMunites = ConvertToMinutes(time.hours, time.minutes);
            int timeAfterAdditionInMinutes = timeInMunites - minutes;

            int hoursAfterConversion = 0;
            int minutesAfterConversion = 0;
            ConvertMinutesToHours(timeAfterAdditionInMinutes, out hoursAfterConversion, out minutesAfterConversion);

            Time timeAfterAddition = new Time(hoursAfterConversion, minutesAfterConversion);
            return timeAfterAddition;
        }

        static private void ConvertMinutesToHours(int minutes, out int outHours, out int outMinutes)
        {
            outHours = minutes / MINUTES_IN_ONE_HOUR;
            outMinutes = minutes % MINUTES_IN_ONE_HOUR;
        }

        private static int ConvertToMinutes(int hours, int minutes)
        {
            int result = hours * MINUTES_IN_ONE_HOUR + minutes;

            return result;
        }
    }
}
